<!-- 任务委托 - 项目负责人 -->
<template>
  <view class="page">
    <u--form
      labelPosition="top"
      :model="basicForm"
      ref="form1"
      labelWidth="auto"
      :labelStyle="{
        fontSize: '14px',
        color: '#B2B2B2',
        lineHight: '20px',
      }"
    >
      <view class="basic-style">
        <view class="basic-title basic-border">基础信息</view>
        <u-form-item label="单据编号" prop="billNo" :borderBottom="false">
          <u--input disabled placeholder="请输入单据编号" v-model="basicForm.billNo" border="surround"></u--input>
        </u-form-item>
        <u-form-item label="申请时间" prop="createTime" :borderBottom="false">
          <u--input
            v-model="basicForm.createTime"
            disabled
            placeholder="请选择时间"
            border="surround"
            suffixIcon="calendar-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></u--input>
        </u-form-item>
        <u-form-item label="申请人" prop="handlerId" :borderBottom="false">
          <h-select-person-input
            style="width: 100%"
            disabled
            v-model="basicForm.handlerId"
            placeholder="请选择申请人"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            objectField="basicForm.handlerId"
          ></h-select-person-input>
        </u-form-item>
        <u-form-item label="申请部门" prop="handlerDeptId" :borderBottom="false">
          <h-select-depart-input
            disabled
            v-model="basicForm.handlerDeptId"
            :departName="basicForm.proposerDeptText"
            placeholder="请选择部门"
            border="surround"
            style="width: 100%"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            :title.sync="basicForm.proposerDeptText"
          ></h-select-depart-input>
        </u-form-item>
      </view>
      <view class="basic-style">
        <view class="basic-title basic-border">项目信息</view>

        <u-form-item label="项目名称" prop="projectName" :borderBottom="false" required>
          <u--input
            disabled
            placeholder="请选择项目名称"
            v-model="basicForm.projectName"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></u--input>
        </u-form-item>
        <u-form-item label="项目编号" prop="finalNo" :borderBottom="false">
          <u--input v-model="basicForm.finalNo" disabled placeholder="请输入项目编号" border="surround"></u--input>
        </u-form-item>
        <u-form-item label="经营团队" prop="teamName" :borderBottom="false">
          <h-select-team-input
            disabled
            style="width: 100%"
            v-model="basicForm.teamName"
            objectField="basicForm.teamName"
            placeholder="请选择经营团队"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            :tdlx="1"
          ></h-select-team-input>
        </u-form-item>
        <u-form-item label="项目承接人" prop="undertaker" :borderBottom="false">
          <h-select-person-input
            style="width: 100%"
            disabled
            v-model="basicForm.undertaker"
            placeholder="请选择项目承接人"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            objectField="basicForm.undertaker"
          ></h-select-person-input>
        </u-form-item>
        <u-form-item label="立项日期" prop="projectEstablishDate" :borderBottom="false">
          <u--input
            v-model="basicForm.projectEstablishDate"
            disabled
            placeholder="请选择立项日期"
            border="surround"
            suffixIcon="calendar-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></u--input>
        </u-form-item>
        <u-form-item label="签订单位" prop="signUnit" :borderBottom="false">
          <h-select-company-input
            disabled
            style="width: 100%"
            v-model="basicForm.signUnit"
            border="surround"
            placeholder="请选择签订单位"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            objectField="basicForm.signUnit"
          ></h-select-company-input>
        </u-form-item>
        <u-form-item label="业绩归属年度" prop="year" :borderBottom="false">
          <h-dict-select
            style="width: 100%"
            v-model="basicForm.year"
            disabled
            placeholder="请选择业绩归属年度"
            dictName="yjgsnd"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></h-dict-select>
        </u-form-item>

        <u-form-item label="业主单位" prop="ownerUnit" :borderBottom="false">
          <h-select-customer-input
            disabled
            style="width: 100%"
            v-model="basicForm.ownerUnit"
            commercialType="1"
            border="surround"
            placeholder="请选择业主单位"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            objectField="basicForm.ownerUnit"
          ></h-select-customer-input>
        </u-form-item>
        <u-form-item label="联系人" prop="contacts" :borderBottom="false">
          <h-dict-select
            style="width: 100%"
            v-model="basicForm.contacts"
            disabled
            placeholder="请选择联系人"
            :dictName="cust_lxr"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></h-dict-select>
        </u-form-item>
        <u-form-item label="联系方式" prop="contactTel" :borderBottom="false">
          <u--input v-model="basicForm.contactTel" disabled placeholder="请输入联系方式"></u--input>
        </u-form-item>
        <u-form-item label="项目所在地址" prop="areaCode" :borderBottom="false">
          <h-select-address-input
            disabled
            style="width: 100%"
            v-model="basicForm.areaCode"
            placeholder="请选择项目地址"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></h-select-address-input>
        </u-form-item>
        <u-form-item label="项目详细地址" prop="projectAddress" :borderBottom="false">
          <u--input v-model="basicForm.projectAddress" disabled placeholder="请输入项目详细地址"></u--input>
        </u-form-item>
        <u-form-item label="项目来源" prop="projectSource" :borderBottom="false">
          <h-dict-select
            style="width: 100%"
            v-model="basicForm.projectSource"
            disabled
            placeholder="请选择项目来源"
            dictName="xmly_type"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></h-dict-select>
        </u-form-item>
        <u-form-item label="预计合同额(元)" prop="estimatedContractAmount" :borderBottom="false">
          <u--input v-model="basicForm.estimatedContractAmount" disabled placeholder="请输入预计合同额"></u--input>
        </u-form-item>
        <u-form-item label="预计合同额大写" prop="estimatedContractcapitalChineseAmount" :borderBottom="false">
          <u--input v-model="basicForm.estimatedContractcapitalChineseAmount" disabled placeholder="请输入预计合同额大写"></u--input>
        </u-form-item>
        <u-form-item label="立项事由及说明" prop="establishReason" :borderBottom="false">
          <u--textarea
            v-model="basicForm.establishReason"
            :maxlength="500"
            disabled
            confirmType="done"
            placeholder="请输入立项事由及说明"
          ></u--textarea>
        </u-form-item>
        <u-form-item label="项目附件" prop="attachment" :borderBottom="false">
          <file-list v-model="basicForm.attachment"></file-list>
        </u-form-item>
      </view>

      <view class="basic-style">
        <view class="basic-title basic-border">任务信息</view>

        <u-form-item label="任务编号" prop="taskNo" :borderBottom="false" required>
          <u--input
            v-model="basicForm.taskNo"
            disabled
            placeholder="请选择任务编号"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></u--input>
        </u-form-item>
        <u-form-item label="业务分类" prop="categoryName" :borderBottom="false">
          <u--input
            v-model="basicForm.categoryName"
            disabled
            placeholder="请选择业务分类"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></u--input>
        </u-form-item>
        <u-form-item label="合同占比(%)" prop="contractRate" :borderBottom="false">
          <u--input
            v-model="basicForm.contractRate"
            disabled
            placeholder="请选择合同占比"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></u--input>
        </u-form-item>
        <u-form-item label="合同分配额(元)" prop="contractAmount" :borderBottom="false">
          <u--input
            v-model="basicForm.contractAmount"
            disabled
            placeholder="请选择合同分配额"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></u--input>
        </u-form-item>
        <u-form-item label="切割合同额(元)" prop="cutContractAmount" :borderBottom="false">
          <u--input
            v-model="basicForm.cutContractAmount"
            disabled
            placeholder="请选择切割合同额"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></u--input>
        </u-form-item>
        <u-form-item label="生产团队" prop="productTeam" :borderBottom="false">
          <h-select-team-input
            style="width: 100%"
            disabled
            v-model="basicForm.productTeam"
            objectField="basicForm.productTeam"
            placeholder="请选择生产团队"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            :tdlx="2"
          ></h-select-team-input>
        </u-form-item>
        <!-- <u-form-item
          label="生产公司"
          prop="productCompanyId"
          :borderBottom="false"
        >
          <h-select-company-input
            disabled
            style="width: 100%"
            v-model="basicForm.productCompanyId"
            border="surround"
            placeholder="请选择生产公司"
            objectField="basicForm.productCompanyId"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{color: '#B2B2B2'}"
          ></h-select-company-input>
          </u-form-item> -->
        <u-form-item label="任务类型" prop="taskType" :borderBottom="false">
          <h-dict-select
            style="width: 100%"
            disabled
            v-model="basicForm.taskType"
            placeholder="请选择任务类型"
            dictName="task_type"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
          ></h-dict-select>
        </u-form-item>
        <u-form-item label="实施部门" prop="executeDepart" :borderBottom="false">
          <h-select-depart-input
            v-model="basicForm.executeDepart"
            :departName="basicForm.executeDepartText"
            placeholder="请选择部门"
            disabled
            border="surround"
            style="width: 100%"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            :title.sync="basicForm.executeDepartText"
            @detail="onExecuteDepartInput"
          ></h-select-depart-input>
        </u-form-item>
        <u-form-item label="部门负责人" prop="minister" :borderBottom="false">
          <h-select-person-input
            style="width: 100%"
            disabled
            v-model="basicForm.minister"
            placeholder="请选择部门负责人"
            border="surround"
            isMulti
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            objectField="basicForm.minister"
          ></h-select-person-input>
        </u-form-item>
        <u-form-item label="项目负责人" prop="projectLeading" :borderBottom="false">
          <h-select-person-input
            style="width: 100%"
            disabled
            v-model="basicForm.projectLeading"
            placeholder="请选择项目负责人"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            objectField="basicForm.projectLeading"
          ></h-select-person-input>
        </u-form-item>
        <template v-if="basicForm.taskType == 1 || basicForm.taskType == 4">
          <u-form-item v-if="basicForm.taskType == 1" label="审核工程师" prop="approvalEngineer" :borderBottom="false">
            <h-select-person-input
              style="width: 100%"
              disabled
              v-model="basicForm.approvalEngineer"
              placeholder="请选择审核工程师"
              border="surround"
              suffixIcon="arrow-down-fill"
              :suffixIconStyle="{ color: '#B2B2B2' }"
              objectField="basicForm.approvalEngineer"
            ></h-select-person-input>
          </u-form-item>
          <u-form-item label="审批级别" prop="approvalLevel" :borderBottom="false">
            <h-dict-select
              style="width: 100%"
              disabled
              v-model="basicForm.approvalLevel"
              placeholder="请选择审批级别"
              dictName="approval_level"
              suffixIcon="arrow-down-fill"
              :suffixIconStyle="{ color: '#B2B2B2' }"
            ></h-dict-select>
          </u-form-item>
          <u-form-item label="审批系数" prop="approvalCoefficient" :borderBottom="false">
            <u--input
              v-model="basicForm.approvalCoefficient"
              type="number"
              disabled
              @blur="onBlur(basicForm.approvalCoefficient, 'approvalCoefficient')"
              placeholder="请选择审批系数"
              border="surround"
            ></u--input>
          </u-form-item>
          <u-form-item label="行业类别" prop="industryCategory" :borderBottom="false">
            <h-dict-select
              style="width: 100%"
              disabled
              v-model="basicForm.industryCategory"
              placeholder="请选择行业类别"
              dictName="industry_category"
              suffixIcon="arrow-down-fill"
              :suffixIconStyle="{ color: '#B2B2B2' }"
            ></h-dict-select>
          </u-form-item>
          <u-form-item label="行业系数" prop="industryCoefficient" :borderBottom="false">
            <u--input
              v-model="basicForm.industryCoefficient"
              placeholder="请输入行业系数"
              type="number"
              disabled
              @blur="onBlur(basicForm.industryCoefficient, 'industryCoefficient')"
              border="surround"
            ></u--input>
          </u-form-item>
          <u-form-item label="复杂程度" prop="complexity" :borderBottom="false">
            <h-dict-select
              style="width: 100%"
              disabled
              v-model="basicForm.complexity"
              placeholder="请选择复杂程度"
              dictName="industry_coefficient"
              suffixIcon="arrow-down-fill"
              :suffixIconStyle="{ color: '#B2B2B2' }"
            ></h-dict-select>
          </u-form-item>
          <u-form-item label="复杂系数" prop="complexCoefficient" :borderBottom="false">
            <u--input
              v-model="basicForm.complexCoefficient"
              type="number"
              disabled
              @blur="onBlur(basicForm.complexCoefficient, 'complexCoefficient')"
              placeholder="请输入复杂系数"
              border="surround"
            ></u--input>
          </u-form-item>
        </template>
        <!-- 当任务类型为检验检测时，展示本项 -->
        <template v-if="basicForm.taskType == 2">
          <u-form-item label="是否出具报告" prop="isOutReport" :borderBottom="false" required>
            <h-dict-radio v-model="basicForm.isOutReport" dictName="YES_OR_NO"></h-dict-radio>
          </u-form-item>
          <u-form-item label="费用核算方式" prop="expenseAccountingMethod" :borderBottom="false">
            <h-dict-select
              style="width: 100%"
              disabled
              v-model="basicForm.expenseAccountingMethod"
              placeholder="请选择费用核算方式"
              dictName="expense_accounting_method"
              suffixIcon="arrow-down-fill"
              :suffixIconStyle="{ color: '#B2B2B2' }"
            ></h-dict-select>
          </u-form-item>
        </template>
        <u-form-item label="说明" prop="instruction" :borderBottom="false">
          <u--textarea v-model="basicForm.instruction" confirmType="done" :maxlength="500" placeholder="请输入说明"></u--textarea>
        </u-form-item>
      </view>

      <view class="basic-style">
        <!-- ManagerEntrustType -->
        <view class="basic-title basic-border">项目成员</view>
        <template>
          <view class="inforamtion" style="display: flex" v-for="(item, index) in distributionDtList" :key="index">
            <view>
              <view class="option" style="width: 520rpx">
                <view class="lf">项目成员</view>
                <view class="rl">{{ filterMultiDictText(dictOptions['projectMember'], item.projectMember + '') }}</view>
              </view>
              <view class="option" style="width: 520rpx">
                <view class="lf">分配合同额(元)</view>
                <view class="rl">{{ item.contractAmount }}</view>
              </view>
              <view class="option" style="width: 520rpx">
                <view class="lf">合同额占比(%)</view>
                <view class="rl">{{ item.contractRate }}</view>
              </view>
              <view class="option" style="width: 520rpx">
                <view class="lf">工时单价(元)</view>
                <view class="rl">{{ item.dayCost }}</view>
              </view>
              <view class="option" style="width: 520rpx">
                <view class="lf">预算工时(小时)</view>
                <view class="rl">{{ item.expectWorkTime }}</view>
              </view>
              <view class="option" style="width: 520rpx">
                <view class="lf">项目绩效(元)</view>
                <view class="rl">{{ item.projectPerformance }}</view>
              </view>
              <view class="option" style="width: 520rpx">
                <view class="lf">人工成本(元)</view>
                <view class="rl">{{ item.laborCost }}</view>
              </view>
            </view>
            <view style="flex: 1; display: flex; align-items: center; justify-content: flex-end">
              <u-icon name="edit-pen-fill" color="#2979ff" size="20" @click="onManagerEntrustEdit(item, index)"></u-icon>
              <u-line direction="col" length="20" margin="0 10rpx" v-if="!item.isProjectLeading"></u-line>
              <u-icon name="trash-fill" v-if="!item.isProjectLeading" color="#2979ff" size="20" @click="onManagerEntrustDelete(item, index)"></u-icon>
            </view>
          </view>
        </template>
        <view style="margin: 20rpx 20rpx 0rpx 20rpx">
          <u-button text="新增" type="primary" @click="onManagerEntrustAdd"></u-button>
        </view>
      </view>

      <view class="basic-style">
        <view class="basic-title basic-border">项目预算</view>
        <u-form-item label="预算总工时(人小时)" prop="expectWorkTime" :borderBottom="false" required>
          <u--input
            disabled
            v-model="basicForm.expectWorkTime"
            type="number"
            @blur="onBlur(basicForm.expectWorkTime, 'expectWorkTime')"
            placeholder="请输入预算总工时"
            border="surround"
          ></u--input>
        </u-form-item>
				<u-form-item label="生产总绩效(元)" prop="totalProductPerformance">
				  <u--input type="number" disabled  placeholder="请输入生产总绩效" v-model="basicForm.totalProductPerformance"></u--input>
				</u-form-item>
        <u-form-item label="人工总成本(元)" prop="workCost" :borderBottom="false">
          <u--input
            disabled
            v-model="basicForm.workCost"
            type="number"
            @blur="onBlurBaicMoney(basicForm.workCost, 'workCost')"
            placeholder="请输入人工成本"
            border="surround"
          ></u--input>
        </u-form-item>

        <u-form-item label="委外费(元)" prop="outsourcingFee" :borderBottom="false" required>
          <u--input
            v-model="basicForm.outsourcingFee"
            type="number"
            @blur="onBlurBaicMoney(basicForm.outsourcingFee, 'outsourcingFee')"
            placeholder="请输入委外费"
            border="surround"
          ></u--input>
        </u-form-item>
        <u-form-item label="差旅费(元)" prop="travelFee" :borderBottom="false" required>
          <u--input
            v-model="basicForm.travelFee"
            type="number"
            @blur="onBlurBaicMoney(basicForm.travelFee, 'travelFee')"
            placeholder="请输入差旅费"
            border="surround"
          ></u--input>
        </u-form-item>
        <u-form-item label="专家评审费(元)" prop="professionReviewFee" :borderBottom="false" required>
          <u--input
            v-model="basicForm.professionReviewFee"
            type="number"
            @blur="onBlurBaicMoney(basicForm.professionReviewFee, 'professionReviewFee')"
            placeholder="请输入专家评审费"
            border="surround"
          ></u--input>
        </u-form-item>
        <u-form-item label="其他成本(元)" prop="otherCost" :borderBottom="false" required>
          <u--input
            v-model="basicForm.otherCost"
            type="number"
            @blur="onBlurBaicMoney(basicForm.otherCost, 'otherCost')"
            placeholder="请输入其他成本"
            border="surround"
          ></u--input>
        </u-form-item>
        <u-form-item label="项目预算合计(元)" prop="totalProjectBudget" :borderBottom="false" required>
          <u--input
            disabled
            v-model="basicForm.totalProjectBudget"
            type="number"
            @blur="onBlurBaicMoney(basicForm.totalProjectBudget, 'totalProjectBudget')"
            placeholder="请输入项目预算合计"
            border="surround"
          ></u--input>
        </u-form-item>
				<template v-if="basicForm.categoryName">
					<view v-if="isProjectInformation">
					  <view class="basic-title basic-border">项目预算表</view>
					  <view class="py-1 space-y-1" style="width: 100%">
							<h-upload-file v-model="basicForm.projectBudgetFile" :isIcon="false"></h-upload-file>
							<file-list v-if="basicForm.projectBudgetFile" v-model="basicForm.projectBudgetFile" :isDelete="true"></file-list>
							<view v-else>
								<u-empty
									mode="data"
									text="暂无项目预算表"
									icon="/static/empty/data.png"
								></u-empty>
							</view>
					  </view>
					</view>
					<view v-else>
					  <view class="basic-title basic-border">生产绩效表</view>
					  <view class="py-1 space-y-1" style="width: 100%">
							<h-upload-file v-model="basicForm.productBudgetFile" :isIcon="false"></h-upload-file>
					    <file-list v-if="basicForm.productBudgetFile" v-model="basicForm.productBudgetFile" :isDelete="true"></file-list>
							<view v-else>
								<u-empty
									mode="data"
									text="暂无生产绩效表"
									icon="/static/empty/data.png"
								></u-empty>
							</view>
					  </view>
					</view>
				</template>
      </view>

      <view class="basic-style">
        <view class="basic-title basic-border">任务进度</view>
        <u-form-item label="进度模板" prop="templateId" required :borderBottom="false">
          <h-select-process-template-input
            style="width: 100%"
            v-model="basicForm.templateId"
            objectField="basicForm.templateId"
            placeholder="请选择进度模板"
            border="surround"
            suffixIcon="arrow-down-fill"
            :suffixIconStyle="{ color: '#B2B2B2' }"
            @input="onTemplateDetail"
          ></h-select-process-template-input>
        </u-form-item>
				<u-form-item label="允许添加子节点" prop="isAddChildNode">
				  <h-select-input-tag
						disabled
				    class="w-100"
				    v-model="basicForm.isAddChildNode"
				    objectField="basicForm.isAddChildNode"
				    placeholder="请选择允许添加子节点"
				    border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
				    dictName="yes_no"
				  ></h-select-input-tag>
				</u-form-item>
				<u-form-item label="收入确认方式" prop="confirmIncomeMethod">
				  <h-select-input-tag
				    class="w-100"
						disabled
				    v-model="basicForm.confirmIncomeMethod"
				    objectField="basicForm.confirmIncomeMethod"
				    placeholder="请选择收入确认方式"
				    border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{ color: '#B2B2B2' }"
				    dictName="confirm_income_method"
				  ></h-select-input-tag>
				</u-form-item>
        <u-collapse v-if="progressVoList && progressVoList.length" ref="collapse" :border="false">
          <u-collapse-item title="进度模板" name="Docs guide">
            <template>
              <view class="inforamtion" style="display: flex" v-for="(item, index) in progressVoList" :key="index">
                <view>
                  <view class="option" style="width: 520rpx">
                    <view class="lf">节点名称</view>
                    <view class="rl">{{ item.nodeName }}</view>
                  </view>
                  <view class="option" style="width: 520rpx">
                    <view class="lf">节点进度</view>
                    <view class="rl">{{ item.nodeProgress ? item.nodeProgress + '%' : 0 + '%' }}</view>
                  </view>
									<view class="option" style="width: 520rpx">
									  <view class="lf">收入确认节点</view>
									  <view class="rl">{{ item.isConfirmIncomeNode_dictText }}</view>
									</view>
                </view>
              </view>
            </template>
          </u-collapse-item>
        </u-collapse>
        <view v-else>
          <u-empty mode="data" icon="/static/empty/data.png"></u-empty>
        </view>
      </view>

      <view class="basic-style">
        <!-- ManagerEntrustType -->
        <view class="basic-title basic-border">款项进度</view>
        <template v-if="progressNodeVoList && progressNodeVoList.length">
          <view class="inforamtion" style="display: flex" v-for="(item, index) in progressNodeVoList" :key="index">
            <view>
              <view class="option" style="width: 520rpx">
                <view class="lf">款项名称</view>
                <view class="rl">{{ item.nodeName }}</view>
              </view>
              <view class="option" style="width: 520rpx">
                <view class="lf">金额(元)</view>
                <view class="rl">{{ item.paymentMoney }}</view>
              </view>
              <view class="option" style="width: 520rpx">
                <view class="lf">款项节点说明</view>
                <view class="rl">{{ item.nodeDesc }}</view>
              </view>
              <!-- <view class="option" style="width: 520rpx">
                <view class="lf">是否关联任务</view>
                <view class="rl">
                  {{
                    item.isRelatedTask === '' || item.isRelatedTask === null || item.isRelatedTask === undefined
                      ? ''
                      : item.isRelatedTask == 0
                      ? '否'
                      : '是'
                  }}
                </view>
              </view> -->
              <!-- <view class="option" style="width: 520rpx">
                <view class="lf">是否关联进度</view>
                <view class="rl">
                  {{
                    item.isRelatedTaskNode === '' || item.isRelatedTaskNode === null || item.isRelatedTaskNode === undefined
                      ? ''
                      : item.isRelatedTaskNode == 0
                      ? '否'
                      : '是'
                  }}
                </view>
              </view> -->
              <view class="option" style="width: 520rpx">
                <view class="lf">本任务关联款项金额(元)</view>
                <view class="rl">{{ item.taskPaymentMoney }}</view>
              </view>
              <view class="option" style="width: 520rpx">
                <view class="lf">任务进度</view>
                <view class="rl">{{ item.taskNodeId_dictText }}</view>
              </view>
              <view class="option" style="width: 520rpx">
                <view class="lf">节点进度(%)</view>
                <view class="rl">{{ item.taskProgress }}</view>
              </view>
            </view>
            <view style="flex: 1; display: flex; align-items: center; justify-content: flex-end">
              <text style="color: #2979ff" @click="onProgressNodeEdit(item, index)">完善</text>
              <!-- <u-icon name="edit-pen-fill" color="#2979ff" size="20" @click="onProgressNodeEdit(item, index)"></u-icon> -->
              <!-- <u-line  direction="col" length="20" margin="0 10rpx"></u-line> -->
              <!-- <u-icon  name="trash-fill" color="#2979ff" size="20"  @click="onProgressNodeDelete(item, index)"></u-icon> -->
            </view>
          </view>
        </template>

        <view v-else>
          <u-empty mode="data" icon="/static/empty/data.png"></u-empty>
        </view>
        <!-- <view  style="margin: 20rpx 20rpx 0rpx 20rpx;">
					<u-button text="新增" type="primary" @click="onProgressNodeAdd"></u-button>
				</view> -->
      </view>
    </u--form>

    <!-- 附件 -->
    <view class="basic-style">
      <view class="basic-title basic-border">任务附件</view>
      <view class="" style="width: 100%">
        <h-upload-file v-model="basicForm.taskFile" :isIcon="false"></h-upload-file>
        <file-list v-if="basicForm.taskFile" v-model="basicForm.taskFile" :isDelete="true"></file-list>
      </view>
    </view>

    <view class="space-x-1 px-1 btn_position">
    	<backButton  @onSubmit="onSubmit" :nodeObj="nodeObj" :model="model" :resultObj="resultObj"></backButton>
    </view>
    <view style="height: 100rpx;"></view>
		
    <!-- 项目成员情况 -->
    <u-popup
      :show="showManagerTrusteePopup"
      @close="closeManagerTrusteePopup"
      :round="10"
      :customStyle="{ maxHeight: '600px', padding: '20rpx 0' }"
    >
      <view style="background-color: #ffffff; border-radius: 10px; padding: 20rpx; overflow: auto">
        <u--form
          labelPosition="top"
          :model="managerTrusteeForm"
          ref="form1"
          labelWidth="auto"
          :labelStyle="{
            fontSize: '14px',
            color: '#B2B2B2',
            lineHight: '40rpx',
          }"
        >
          <u-form-item label="项目成员" prop="projectMember" :borderBottom="false" required>
            <h-select-person-input-popup
              style="width: 100%"
              v-model="managerTrusteeForm.projectMember"
							:disabled="managerTrusteeForm.isProjectLeading"
              placeholder="请选择项目成员"
              searchPlaceholder="请输入用户姓名"
              border="surround"
              suffixIcon="arrow-down-fill"
              :suffixIconStyle="{ color: '#B2B2B2' }"
              objectField="managerTrusteeForm.projectMember"
              @change="handleMemberChange"
            ></h-select-person-input-popup>
          </u-form-item>
          <u-form-item label="分配合同额(元)" prop="contractAmount" :borderBottom="false" required>
            <u--input
              v-model="managerTrusteeForm.contractAmount"
              placeholder="请输入分配合同额"
              border="surround"
              type="number"
              @change="moneyChange"
              @blur="onMoneyBlur(managerTrusteeForm.contractAmount)"
            ></u--input>
          </u-form-item>
          <u-form-item label="合同额占比(%)" prop="contractRate" :borderBottom="false">
            <u--input
              v-model="managerTrusteeForm.contractRate"
              placeholder="成员匹配合同额/任务委托合同额"
              border="surround"
              type="number"
              disabled
            ></u--input>
          </u-form-item>
          <u-form-item label="工时单价(元)" prop="dayCost" :borderBottom="false">
            <h-number-input
              disabled
              placeholder="请输入工时单价"
              v-model="managerTrusteeForm.dayCost"
              border="surround"
              :digit="2"
              :max="99999999"
              :min="2"
            ></h-number-input>
            <!-- <u--input v-model="managerTrusteeForm.dayCost" placeholder="请输入工时单价" border="surround" type="number" disabled></u--input> -->
          </u-form-item>
          <!-- <u-form-item label="预算工时(人天)" prop="expectWorkTime" :borderBottom="false" required> -->
          <!-- <u--input v-model="managerTrusteeForm.expectWorkTime" placeholder="请输入预算工时" border="surround" type="number"></u--input> -->
          <!-- </u-form-item> -->
          <u-form-item label="预算工时(小时)" prop="expectWorkTime" required>
            <h-number-input
              placeholder="请输入预算工时"
              v-model="managerTrusteeForm.expectWorkTime"
              border="surround"
              :digit="1"
              :max="99999999"
              :min="0"
              suffixIcon="edit-pen-fill"
            ></h-number-input>
          </u-form-item>
          <u-form-item label="项目绩效(元)" prop="projectPerformance" :borderBottom="false" required>
            <h-number-input
              placeholder="请输入项目绩效"
              v-model="managerTrusteeForm.projectPerformance"
              border="surround"
              :digit="2"
              :max="99999999"
              :min="0"
              suffixIcon="edit-pen-fill"
            ></h-number-input>
          </u-form-item>
          <u-form-item label="人工成本(元)" prop="laborCost" :borderBottom="false" required>
						<u--input
						  v-model="managerTrusteeForm.laborCost"
						  placeholder="请输入人工成本"
						  border="surround"
						  type="number"
						  disabled
						></u--input>
          </u-form-item>
        </u--form>
        <view style="padding-bottom: 20rpx">
          <u-button text="确定" type="primary" @click="onConfirmManagerTrusteePopup"></u-button>
        </view>
      </view>
    </u-popup>

    <!-- 完善列表 -->
    <u-popup
      :show="showProgressNodePopup"
      @close="closeProgressNodePopup"
      :round="10"
      :customStyle="{ maxHeight: '600px', padding: '20rpx 0' }"
    >
      <view style="background-color: #ffffff; border-radius: 10px; padding: 20rpx; overflow: auto">
        <u--form
          labelPosition="top"
          :model="progressNodeForm"
          ref="form1"
          labelWidth="auto"
          :labelStyle="{
            fontSize: '14px',
            color: '#B2B2B2',
            lineHight: '40rpx',
          }"
        >
          <u-form-item label="款项名称" prop="nodeName" :borderBottom="false">
            <u--input v-model="progressNodeForm.nodeName" placeholder="请输入款项名称" disabled border="surround"></u--input>
          </u-form-item>
          <u-form-item label="金额(元)" prop="paymentMoney" :borderBottom="false">
            <u--input v-model="progressNodeForm.paymentMoney" placeholder="请输入金额" border="surround" disabled type="number"></u--input>
          </u-form-item>
          <u-form-item label="款项节点说明" prop="nodeDesc" :borderBottom="false">
            <u--textarea v-model="progressNodeForm.nodeDesc" disabled confirmType="done" placeholder="请输入款项节点说明"></u--textarea>
          </u-form-item>
					<u-form-item label="任务进度" prop="taskNodeId" :borderBottom="false" required>
					  <selectTaskProgressInput
					    style="width: 100%"
					    v-model="progressNodeForm.taskNodeId"
					    :progressVoList="progressVoList"
					    objectField="progressNodeForm.templateId"
					    placeholder="请选择任务进度"
					    border="surround"
					    suffixIcon="arrow-down-fill"
					    :suffixIconStyle="{ color: '#B2B2B2' }"
					    @detail="onTaskChange"
					  ></selectTaskProgressInput>
					</u-form-item>
					<u-form-item label="本任务关联款项金额(元)" prop="taskPaymentMoney" :borderBottom="false">
					  <u--input v-model="progressNodeForm.taskPaymentMoney" placeholder="请输入本任务关联款项金额" border="surround" disabled type="number"></u--input>
					</u-form-item>
          <!-- <u-form-item label="是否关联任务" prop="isRelatedTask" :borderBottom="false" required>
            <h-dict-radio v-model="progressNodeForm.isRelatedTask" dictName="YES_OR_NO" @input="relatedTaskChange"></h-dict-radio>
          </u-form-item> -->
          <!-- <template v-if="progressNodeForm.isRelatedTask == 1">
            <u-form-item label="是否关联进度" prop="isRelatedTaskNode" :borderBottom="false" required>
              <h-dict-radio v-model="progressNodeForm.isRelatedTaskNode" dictName="YES_OR_NO" @input="relatedTaskNodeChange"></h-dict-radio>
            </u-form-item>
            
          </template> -->
        </u--form>
        <view style="padding-bottom: 20rpx">
          <u-button text="确定" type="primary" @click="onConfirmProgressNodePopup"></u-button>
        </view>
      </view>
    </u-popup>
    <u-toast ref="uToast"></u-toast>
  </view>
</template>

<script>
import http from '@/utils/request'
import fileList from './components/fileList.vue'
import backButton from '@/components/backButton.vue'
import selectTaskProgressInput from './components/selectTaskProgressInput.vue'
import { filterMultiDictText, initDictOptions } from '@/utils/JDictSelectUtil.js'
import {
	getProcessTaskTransInfo, // 流程流转
  erpOmcTaskDistributionId, // 根据id查询任务委托详情
  erpOmcProjectId, // 获取项目详情
  erpOmcTaskDistributionDtList, // 获取项目成员列表
  erpOmcTaskDistributionEdit, // 编辑
  queryUsersByUsernames, // 部门负责人带入
  queryPayGradeByEmpId,
  erpProgressTemplateDtList, // 进度模板
  erpOmcTaskDistributionPaymentList, // 款项进度列表
  erpOmcTaskDistributionPaymentNodeList, // 款项进度编辑列表
} from '@/api/index.js'
import { BASE_URL } from '@/utils/baseUrl.js'
import { convertCurrency } from '@/utils/MoneyConvert' // 金额大写转换
import { mapState } from 'vuex'
import Decimal from 'decimal.js'
export default {
  components: {
    fileList,
    selectTaskProgressInput,
		backButton
  },
  data() {
    return {
			resultObj: {}, // 流程图流转信息
      isFirst: true, // 是否第一次进入此页面
      progressVoList: [], // 进度模板
      progressNodeVoList: [], // 款项进度列表
      progressNodeVoListInitial: [], // 款项进度列表
      showProgressNodePopup: false, // 完善弹窗显隐
      progressNodeForm: {
        nodeName: '',
        paymentMoney: '',
        nodeDesc: '',
        taskNodeId: '',
				taskProgress: ''
      }, // 款项进度对象
      progressNodePopupIndex: 0, // 选择的数据
      filterMultiDictText,
      initDictOptions,
      dictOptions: {},
      cust_lxr: 'erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id=0',
      distributionDtList: [], // 项目成员列表
      showManagerTrusteePopup: false, // 弹窗开关
      clickManagerEntrustPopup: '', // 点击编辑还是新增
      commissionedIndex: 0, // 点击编辑的index值
      managerTrusteeForm: {
        projectMember: '',
        contractAmount: '',
        contractRate: '',
      }, // 对象

      isRefresh: false, // 获取项目信息时是否清空数据 false - 不清空
      isContractNoInfoRefresh: false, // 获取合同信息时是否清空数据 false - 不清空
      isSubmit: false,
      basicForm: {},
      nodeObj: {},
      tabvalue: '',
      id: '', // 详情id值
      model: {},

      clickManagerTrusteePopup: '', // 点击编辑还是新增

      managerTrusteeIndex: 0, // 点击编辑的index值
      userInformation: '', // 用户信息
    }
  },
  onLoad(options) {
    // 获取用户信息
    this.userInformation = this.userInfo()
    this.model = JSON.parse(decodeURIComponent(options.item))
    this.initDictConfig()
    var that = this
		var eventChannel = ''
    // #ifdef APP-NVUE
    eventChannel = this.$scope.eventChannel // 兼容APP-NVUE
    // #endif
    // #ifndef APP-NVUE
    eventChannel = this.getOpenerEventChannel()
    // #endif
    // 监听sendMessage事件，获取上一页面通过eventChannel传送到当前页面的数据
    eventChannel.on('sendMessage', function (data) {
      that.tabvalue = data.tabvalue
      that.nodeObj = JSON.parse(decodeURIComponent(data.nodeObj))
      that.id = that.nodeObj.dataId
      that.loadData(that.nodeObj.dataId)
			that.getProcessTaskTrans(that.model.id)
    })
  },
  computed: {
    rate() {
      return [this.basicForm.contractAmount, this.managerTrusteeForm.contractAmount]
    },
    laborCost() {
      return [this.managerTrusteeForm.dayCost, this.managerTrusteeForm.expectWorkTime, this.managerTrusteeForm.projectPerformance]
    },
    projectTotal() {
      return [
        this.basicForm.workCost,
        this.basicForm.outsourcingFee,
        this.basicForm.travelFee,
        this.basicForm.professionReviewFee,
        this.basicForm.otherCost,
      ]
    },
		// 判断是否为工程运维或者数字信息的业务分类
		isProjectInformation() {
			// 判断categoryName是否含有工程运维或者数字信息
			if (this.basicForm.categoryName && (this.basicForm.categoryName.indexOf('工程运维') !== -1 || this.basicForm.categoryName.indexOf('数字信息') !== -1)) {
				return true
			} else {
				return false
			}
		}
  },
  watch: {
    rate: {
      handler() {
        if (this.managerTrusteeForm.contractAmount === null || this.managerTrusteeForm.contractAmount === '') {
          this.managerTrusteeForm.contractAmount = null
          this.managerTrusteeForm.contractRate = null
          return
        }
				if (!Number(this.basicForm.contractAmount)) {
					return this.managerTrusteeForm.contractRate = 0.00
				}
        let rate = new Decimal(this.managerTrusteeForm.contractAmount).div(this.basicForm.contractAmount).mul(100)
        this.managerTrusteeForm.contractRate = rate.toFixed(2)
      },
      immediate: true,
    },
    laborCost: {
      handler() {
        const { dayCost, expectWorkTime, projectPerformance } = this.managerTrusteeForm
        const format = (num) => Number(num) || 0

        function parse(num) {
          return Number(Number(num).toFixed(2))
        }

        this.managerTrusteeForm.laborCost = (parse(format(dayCost) * format(expectWorkTime) / 8 + format(projectPerformance))).toFixed(2)
        // const { dayCost, expectWorkTime, projectPerformance } = this.managerTrusteeForm
        // const format = (num) => Number(num) || 0

        // this.managerTrusteeForm.laborCost = (format(dayCost) * format(expectWorkTime) + format(projectPerformance)).toFixed(2)
      },
      immediate: true,
    },
    distributionDtList: {
      handler(val) {
        if (!val) return
        const format = (num) => Number(num) || 0
        function parse(num) {
          return Number(Number(num).toFixed(2))
        }
        // 所有成员的预算工时之和
        this.basicForm.expectWorkTime = parse(
          val.reduce((total, item) => {
            return total + format(item.expectWorkTime)
          }, 0),
        )

        // 所有成员的人工成本之和
        this.basicForm.workCost = parse(
          val.reduce((total, item) => {
            return total + format(item.laborCost)
          }, 0),
        ),
				// 所有成员的项目绩效之和
				this.basicForm.totalProductPerformance = parse(
          val.reduce((total, item) => {
            return total + format(item.projectPerformance)
          }, 0),
        )
      },
      immediate: true,
      deep: true,
    },
    projectTotal() {
      function parse(num) {
        return Number(num) || 0
      }
      this.basicForm.totalProjectBudget = new Decimal(this.basicForm.workCost || 0)
        .plus(parse(this.basicForm.outsourcingFee))
        .plus(parse(this.basicForm.travelFee))
        .plus(parse(this.basicForm.professionReviewFee))
        .plus(parse(this.basicForm.otherCost))
        .toNumber()
    },
  },
  methods: {
    handleMemberChange(item) {
      if (!item) return

      queryPayGradeByEmpId({ empId: item.empId }).then((response) => {
        // debugger
        this.$set(this.managerTrusteeForm, 'dayCost', response.result)
      })
    },
    ...mapState(['userInfo']),
    loadData(id) {
      erpOmcTaskDistributionId({ id }).then(async (res) => {
        if (res.success) {
          this.cust_lxr = (await "erp_omc_customer_manager_contact,lxr,id,del_flag=0 and main_id='") + res.result.ownerUnit + "'"
          this.basicForm = await res.result
          if (this.basicForm && this.basicForm.templateId) {
            this.isFirst = true
          } else {
            this.isFirst = false
          }
          // 获取项目编号
          this.projectNumber(res.result.projectId)
          this.taskNumber(res.result.taskId)
          this.getMemberList(res.result.id) // 获取项目成员列表
          this.queryPaymentNodeListByMainId(res.result.id) // 获取款项进度列表
          this.queryPaymentListByProjectId(this.basicForm.taskId) // 获取款项进度列表
          // 获取编辑任务进度列表
          if (res.result.id) {
            this.getEditTemplateDtList(res.result.id)
          }
        } else {
          this.$refs.uToast.show({
            message: res.message,
            type: 'error',
          })
        }
      })
    },

    // 获取项目编号
    projectNumber(projectId) {
      erpOmcProjectId({ id: projectId }).then((res) => {
        if (res.success) {
          this.$set(this.basicForm, 'finalNo', res.result.finalNo) // 项目编号
        } else {
          this.$refs.uToast.show({
            message: res.message,
            type: 'error',
          })
        }
      })
    },
    // 获取任务编号
		taskNumber(taskId) {
		  http.get('/api/erp/omc/project/erpOmcProjectTask/queryById', { id: taskId }).then((res) => {
		    if (res.success) {
		      var event = res.result
		      this.$set(this.basicForm, 'taskNo', event.billNo?event.billNo: taskId) // 任务编号
		    } else {
					this.$set(this.basicForm, 'taskNo', taskId) // 任务编号
		      this.$refs.uToast.show({
		        message: res.message,
		        type: 'error',
		      })
		    }
		  }).catch(err => {
				this.$set(this.basicForm, 'taskNo', taskId) // 任务编号
			})
		},

    // 获取项目成员列表
    getMemberList(mainId) {
      erpOmcTaskDistributionDtList({ mainId }).then((res) => {
        if (res.success) {
          this.distributionDtList = res.result || []
          this.distributionDtList = this.addProjectLeading(this.distributionDtList)
        } else {
          this.$refs.uToast.show({
            message: res.message,
            type: 'error',
          })
        }
      })
    },
		addProjectLeading(distributionDtList = []) {
		      // 查询项目成员列表中是否包含项目负责人，如果不包含就需要添加项目负责人
		      if (distributionDtList.length > 0) {
		        // 先全部置为false，再判断是否包含basicForm.projectLeading，如果不包含就添加项目负责人
		        distributionDtList.forEach((item) => {
		          item.isProjectLeading = false
		        })
		        // 循环遍历distributionDtList，判断是否包含basicForm.projectLeading，如果不包含就添加项目负责人
		        let listIndex = distributionDtList.findIndex(item => item.projectMember == this.basicForm.projectLeading)
		        if (listIndex === -1) {
		          distributionDtList.unshift({
		            projectMember: this.basicForm.projectLeading, // 添加项目负责人
		            id: parseInt(Math.random() * 1000000000000),
		            mainId: this.mainId,
		            contractAmount: null,
		            contractRate: null,
		            dayCost: null,
		            expectWorkTime: null,
		            laborCost: null,
		            projectPerformance: null,
		            isProjectLeading: true // 用于判断该条数据是否为项目负责人
		          })
		          http.get('/api/erp/files/employee/erpEmployeeFile/queryPayGradeByEmpId', { empId: this.basicForm.projectLeading }).then(response => {
		            distributionDtList[0].dayCost = response.result
		          })
		        } else {
							distributionDtList.splice(listIndex, 1, {...distributionDtList[listIndex],isProjectLeading: true }) // 用于判断该条数据是否为项目负责人
		        }
		      } else {
		        distributionDtList.unshift({
		          projectMember: this.basicForm.projectLeading, // 添加项目负责人
		          id: parseInt(Math.random() * 1000000000000),
		          mainId: this.mainId,
		          contractAmount: null,
		          contractRate: null,
		          dayCost: null,
		          expectWorkTime: null,
		          laborCost: null,
		          projectPerformance: null,
		          isProjectLeading: true // 用于判断该条数据是否为项目负责人
		        })
		        http.get('/api/erp/files/employee/erpEmployeeFile/queryPayGradeByEmpId', { empId: this.basicForm.projectLeading }).then(response => {
		          distributionDtList[0].dayCost = response.result
		        })
		      }
		      return distributionDtList
		    },

    // 获取款项进度列表
    queryPaymentListByProjectId(taskId, flag) {
      this.progressNodeVoList = []
      erpOmcTaskDistributionPaymentList({ taskId }).then((res) => {
        if (res.success) {
          // this.progressNodeVoList = res.result
          this.progressNodeVoListInitial = JSON.parse(JSON.stringify(res.result))
          if (flag == 1) {
            this.progressNodeVoList = res.result
          }
        }
      })
    },
    // 编辑获取款项进度列表
    queryPaymentNodeListByMainId(id) {
      if (!id) {
        return false
      }
      this.progressNodeVoList = []
      erpOmcTaskDistributionPaymentNodeList({ id }).then((res) => {
        if (res.success) {
          this.progressNodeVoList = res.result
        } else {
          this.queryPaymentListByProjectId(this.basicForm.taskId, 1) // 获取款项进度列表
        }
      })
    },

    relatedTaskChange(item) {
      this.$set(this.progressNodeForm, 'isRelatedTaskNode', '0')
      this.$set(this.progressNodeForm, 'taskNodeId', undefined)
      this.$set(this.progressNodeForm, 'taskNodeId_dictText', undefined)
    },

    relatedTaskNodeChange(item) {
      this.$set(this.progressNodeForm, 'taskNodeId', undefined)
      this.$set(this.progressNodeForm, 'taskNodeId_dictText', undefined)
    },

    // 点击完善
    onProgressNodeEdit(item, index) {
      this.progressNodeForm = { ...item }
      this.progressNodePopupIndex = index
      // this.clickManagerEntrustPopup = 'edit'
      var keys = Object.keys(item)
      // 是否关联任务进度
      // if (keys.indexOf('isRelatedTaskNode') == -1 || this.progressNodeForm.isRelatedTaskNode == null) {
      //   this.$set(this.progressNodeForm, 'isRelatedTaskNode', 0)
      // }
      // 是否关联任务
      // if (keys.indexOf('isRelatedTask') == -1 || this.progressNodeForm.isRelatedTask == null) {
      //   this.$set(this.progressNodeForm, 'isRelatedTask', 1)
      // }
      // if (this.progressNodeForm.isRelatedTaskNode == 0) {
      //   // this.$delete(this.validatorRules, 'taskNodeId');
      // }
      this.showProgressNodePopup = true
    },
    // 关闭完善弹窗
    closeProgressNodePopup() {
      this.isRefresh = false
      this.isCheckoutInfoRefresh = false
      this.isContractNoInfoRefresh = false
      this.showProgressNodePopup = false
    },

    // 任务进度详情
    onTaskChange(item) {
      this.$set(this.progressNodeForm, 'taskNodeId_dictText', item.nodeName)
			this.$set(this.progressNodeForm, 'taskProgress', item.nodeProgress || '') // 任务节点进度
    },
    // 完善弹窗确定按钮
    onConfirmProgressNodePopup() {
      // if (
      //   this.progressNodeForm.isRelatedTask === '' ||
      //   this.progressNodeForm.isRelatedTask === null ||
      //   this.progressNodeForm.isRelatedTask === undefined
      // ) {
      //   this.showMessage('请选择是否关联任务')
      //   return
      // }
      // if (
      //   this.progressNodeForm.isRelatedTaskNode === '' ||
      //   this.progressNodeForm.isRelatedTaskNode === null ||
      //   this.progressNodeForm.isRelatedTaskNode === undefined
      // ) {
      //   this.showMessage('请选择是否关联任务进度')
      //   return
      // }
      if (!this.progressNodeForm.taskNodeId) {
        this.showMessage('请选择任务进度')
        return
      }
      this.$set(this.progressNodeForm, 'paymentId', this.progressNodeForm.id)
      this.progressNodeVoList[this.progressNodePopupIndex] = this.progressNodeForm
      // if (this.clickManagerEntrustPopup == 'edit') {
      // 	this.progressNodeVoList[this.commissionedIndex] = this.progressNodeForm
      // } else {
      // 	this.progressNodeForm.mainId = this.basicForm.id
      // 	this.progressNodeForm.id =  parseInt(Math.random() * 1000000000000);
      // 	this.progressNodeVoList.push(this.progressNodeForm)

      // }
      this.showProgressNodePopup = false
      this.progressNodeForm = {
        nodeName: '',
        paymentMoney: '',
        nodeDesc: '',
				taskPaymentMoney: '',
        // isRelatedTask: '',
        // isRelatedTaskNode: '',
        taskNodeId: '',
				taskProgress: ''
      } // 款项进度对象
    },

    // 选择进度模板
    onTemplateDetail(item) {
      this.$set(this.basicForm, 'templateName', item.templateName)
			this.$set(this.basicForm, 'confirmIncomeMethod', item.confirmIncomeMethod || '') // 收入确认方式
			this.$set(this.basicForm, 'isAddChildNode', item.isAddChildNode || '') // 允许添加子节点
      this.progressNodeVoList = JSON.parse(JSON.stringify(this.progressNodeVoListInitial))
      this.getTemplateDtList(item)
    },
    // 获取进度模板
    getTemplateDtList(data) {
      erpProgressTemplateDtList({ mainId: data.id }).then((res) => {
        if (res.success) {
					// 后端无良心，需要前端自己处理，当选择了“允许添加子节点”需要在每一个节点里面塞isAddChildNode值最后一个节点不用塞
					let isAddChildNode = data.isAddChildNode
					res.result.map((item, index) => {
						item.templateNodeId = item.id
						if (index === res.result.length - 1) {
							item.isAddChildNode = '0'
						} else {
							item.isAddChildNode = isAddChildNode
						}
						return item
					})
          this.progressVoList = res.result
          this.$nextTick(() => {
            this.$refs.collapse.init()
          })
        }
      })
    },
		// 获取编辑进度模板
    getEditTemplateDtList(id) {
      http.get('/api/erp/omc/task/erpOmcTaskDistribution/queryTaskNodeListByMainId',{ id }).then((res) => {
        if (res.success) {
					if (res.result && res.result.length) {
					  this.progressVoList = res.result
					}
          this.$nextTick(() => {
            this.$refs.collapse.init()
          })
        }
      })
    },

    initDictConfig() {
      // 人员名称
      initDictOptions('erp_employee_file,name,id').then((res) => {
        if (res.success) {
          // this.$set(this.dictOptions, 'handlerId', res.result)
          // this.$set(this.dictOptions, 'undertaker', res.result)
          // this.$set(this.dictOptions, 'minister', res.result)
          // this.$set(this.dictOptions, 'projectLeading', res.result)
          // this.$set(this.dictOptions, 'approvalEngineer', res.result)
          this.$set(this.dictOptions, 'projectMember', res.result)
        }
      })
      // // 部门名称
      // initDictOptions('sys_depart,depart_name,id').then((res) => {
      // 	if (res.success) {
      // 		this.$set(this.dictOptions, 'handlerDeptId', res.result)
      // 		this.$set(this.dictOptions, 'executeDepart', res.result)
      // 	}
      // })
      // // 团队名称
      // initDictOptions('erp_omc_team_manager,alias_name,id').then((res) => {
      // 	if (res.success) {
      // 		this.$set(this.dictOptions, 'teamName', res.result)
      // 		this.$set(this.dictOptions, 'productTeam', res.result)
      // 	}
      // })
      // // 单位
      // initDictOptions('erp_company_files,file_name,id').then((res) => {
      // 	if (res.success) {
      // 		this.$set(this.dictOptions, 'signUnit', res.result)
      // 	}
      // })
      // // 业主单位
      // initDictOptions('erp_purchase_supplier,enterprise_name,id').then((res) => {
      // 	if (res.success) {
      // 		this.$set(this.dictOptions, 'ownerUnit', res.result)
      // 	}
      // })
      // // 联系人
      // initDictOptions(this.cust_lxr).then((res) => {
      // 	if (res.success) {
      // 		this.$set(this.dictOptions, 'contacts', res.result)
      // 	}
      // })
      // // 项目来源
      // initDictOptions('xmly_type').then((res) => {
      // 	if (res.success) {
      // 		this.$set(this.dictOptions, 'projectSource', res.result)
      // 	}
      // })
      // // 任务类型
      // initDictOptions('task_type').then((res) => {
      // 	if (res.success) {
      // 		this.$set(this.dictOptions, 'taskType', res.result)
      // 	}
      // })
      // // 审批级别
      // initDictOptions('approval_level').then((res) => {
      // 	if (res.success) {
      // 		this.$set(this.dictOptions, 'approvalLevel', res.result)
      // 	}
      // })
      // // 行业类别
      // initDictOptions('industry_category').then((res) => {
      // 	if (res.success) {
      // 		this.$set(this.dictOptions, 'industryCategory', res.result)
      // 	}
      // })
      // // 复杂程度
      // initDictOptions('industry_coefficient').then((res) => {
      // 	if (res.success) {
      // 		this.$set(this.dictOptions, 'complexity', res.result)
      // 	}
      // })
      // // 是否出具报告
      // initDictOptions('YES_OR_NO').then((res) => {
      // if (res.success) {
      // 		this.$set(this.dictOptions, 'isOutReport', res.result)
      // 	}
      // })
      // // 是否出具报告
      // initDictOptions('expense_accounting_method').then((res) => {
      // if (res.success) {
      // 		this.$set(this.dictOptions, 'expenseAccountingMethod', res.result)
      // 	}
      // })
    },

    // 选择实施部门
    onExecuteDepartInput(item) {
      if (!item[0].minister) {
        this.$set(this.basicForm, 'minister', undefined)
        return false
      }
      //
      // 复制部门负责人
      queryUsersByUsernames({ usernames: item[0].minister }).then((res) => {
        var idsArr = []
        var ids = ''
        if (res && res.length) {
          res.map((value) => {
            idsArr.push(value.empId)
          })
        }
        ids = idsArr.toString()

        this.$set(this.basicForm, 'minister', ids)
      })
    },

    // 约束数字输入框
    onBlur(item, text) {
      if (item == undefined || item == null || item === '') {
        return false
      }
      var num = Number(item)
      if (num <= 0) {
        num = 0
      }
      if (num >= 99999) {
        num = 99999
      }
      this.basicForm[text] = num.toFixed(1)
    },
    onBlurBaicMoney(item, text) {
      if (item == undefined || item == null || item === '') {
        return false
      }
      var num = Number(item)
      if (num <= 0) {
        num = 0
      }
      if (num >= 99999999) {
        num = 99999999
      }
      this.basicForm[text] = num.toFixed(2)
    },

    // 点击编辑
    onManagerEntrustEdit(item, index) {
      this.managerTrusteeForm = { ...item }
      this.commissionedIndex = index
      this.clickManagerEntrustPopup = 'edit'
      this.showManagerTrusteePopup = true
    },
    // 点击删除
    onManagerEntrustDelete(item, index) {
      let _this = this
      uni.showModal({
        title: '确定删除',
        content: '确定删除此信息？',
        success(res) {
          if (res.confirm) {
            _this.distributionDtList.splice(index, 1)
          } else if (res.cancel) {
            // 用户点击取消
          }
        },
      })
    },

    // 点击新增
    onManagerEntrustAdd() {
      this.managerTrusteeForm = {
        projectMember: '',
        contractAmount: '',
        contractRate: '',
      } // 对象
      this.clickManagerEntrustPopup = 'add'
      this.showManagerTrusteePopup = true
    },

    //输入金额
    moneyChange(item) {
      function parse(num) {
        return Number(num) || 0
      }
			if (!Number(this.basicForm.contractAmount)) {
				return this.managerTrusteeForm.contractRate = 0.00
			}
      this.managerTrusteeForm.contractRate = new Decimal(parse(this.managerTrusteeForm.contractAmount))
        .div(parse(this.basicForm.contractAmount))
        .mul(100)
        .toFixed(2)
				
    },

    // 金额约束
    onMoneyBlur(item) {
      if (item === undefined || item === null || item === '') {
        return false
      }
      var num = Number(item)
      if (num <= 0) {
        num = 0
      }
      if (num >= 99999999) {
        num = 99999999
      }
      this.managerTrusteeForm.contractAmount = num.toFixed(2)
    },

    showMessage(message) {
      uni.showToast({
        title: message,
        icon: 'none',
      })
    },
    // 子表确定按钮
    onConfirmManagerTrusteePopup() {
      // this.getManagerTrusteeId(this.managerTrusteeForm.gsdaId)
      if (!this.managerTrusteeForm.projectMember) {
        this.showMessage('请选择项目成员！')
        return
      }
      if (
        this.managerTrusteeForm.contractAmount === '' ||
        this.managerTrusteeForm.contractAmount === null ||
        this.managerTrusteeForm.contractAmount === undefined
      ) {
        this.showMessage('请输入分配合同额！')
        return
      }
      if (
        this.managerTrusteeForm.expectWorkTime === '' ||
        this.managerTrusteeForm.expectWorkTime === null ||
        this.managerTrusteeForm.expectWorkTime === undefined
      ) {
        this.showMessage('请输入预算工时！')
        return
      }
      if (
        this.managerTrusteeForm.projectPerformance === '' ||
        this.managerTrusteeForm.projectPerformance === null ||
        this.managerTrusteeForm.projectPerformance === undefined
      ) {
        this.showMessage('请输入项目绩效！')
        return
      }
      // if (this.managerTrusteeForm.contractRate === '' || this.managerTrusteeForm.contractRate === null) {
      //   this.showMessage('请输入合同额占比！')
      //   return
      // }
      if (this.clickManagerEntrustPopup == 'edit') {
        // this.distributionDtList[this.commissionedIndex] = this.managerTrusteeForm
        this.$set(this.distributionDtList, this.commissionedIndex, this.managerTrusteeForm)
      } else {
        this.managerTrusteeForm.mainId = this.basicForm.id
        this.managerTrusteeForm.id = parseInt(Math.random() * 1000000000000)
        this.distributionDtList.push(this.managerTrusteeForm)
      }
      this.showManagerTrusteePopup = false
      this.managerTrusteeForm = {
        projectMember: '',
        contractAmount: '',
        contractRate: '',
      } // 对象
    },

    // 关闭子表弹窗
    closeManagerTrusteePopup() {
      this.isRefresh = false
      this.isCheckoutInfoRefresh = false
      this.isContractNoInfoRefresh = false
      this.showManagerTrusteePopup = false
    },
		
		// 查询流程流转信息 -- 获取下一节点信息
		getProcessTaskTrans(taskId){
			getProcessTaskTransInfo({ taskId }).then(res => {
				if(res.success){
					this.resultObj = res.result
				} else {
					this.$refs.uToast.show({
						message: res.message,
						type: 'error'
					})
				}
			}).catch(err => {
				console.log(err);
			})
		},
		validateNoDuplicateProjectMembers(list) {
			const duplicates = list.filter((item, index) => 
				list.findIndex(i => i.projectMember === item.projectMember) !== index
			);
			if (duplicates.length > 0) {
				return false; // 验证失败
			}
			return true; // 验证通过
		},
    // 点击提交
    onSubmit() {
			var _this = this
      if (!this.distributionDtList || !this.distributionDtList.length) {
        uni.showToast({
          title: '请添加项目成员情况！',
          icon: 'none',
        })
        return false
      }
			const isMemberError = this.distributionDtList.some((item) => {
			return !item.projectMember || (item.contractAmount === undefined || item.contractAmount === null || item.contractAmount === '') || (item.expectWorkTime === undefined || item.expectWorkTime === null || item.expectWorkTime === '') || (item.projectPerformance === undefined || item.projectPerformance === null || item.projectPerformance === '')
		})
		if (isMemberError) {
			uni.showToast({
			  title: '请完善项目成员信息！',
			  icon: 'none',
			})
			return false
		}
		const isRepeat = this.validateNoDuplicateProjectMembers(this.distributionDtList);
		if (!isRepeat) {
			uni.showToast({
			  title: '请勿重复添加项目成员！',
			  icon: 'none',
			})
			return false
		}
      // 检验检测
      if (this.basicForm.taskType == 2) {
        if (this.basicForm.isOutReport == '' || this.basicForm.isOutReport == undefined) {
          uni.showToast({
            title: '请选择是否出具报告！',
            icon: 'none',
          })
          return false
        }
      }
      if (this.basicForm.expectWorkTime === '' || this.basicForm.expectWorkTime === null) {
        uni.showToast({
          title: '请填写预算工时！',
          icon: 'none',
        })
        return false
      }
      if (this.basicForm.workCost === '' || this.basicForm.workCost === null) {
        uni.showToast({
          title: '请填写人工成本！',
          icon: 'none',
        })
        return false
      }
      if (this.basicForm.outsourcingFee === '' || this.basicForm.outsourcingFee === null) {
        uni.showToast({
          title: '请填写委外费！',
          icon: 'none',
        })
        return false
      }
      if (this.basicForm.travelFee === '' || this.basicForm.travelFee === null) {
        uni.showToast({
          title: '请填写差旅费！',
          icon: 'none',
        })
        return false
      }
      if (this.basicForm.professionReviewFee === '' || this.basicForm.professionReviewFee === null) {
        uni.showToast({
          title: '请填写专家评审费！',
          icon: 'none',
        })
        return false
      }
      if (this.basicForm.otherCost === '' || this.basicForm.otherCost === null) {
        uni.showToast({
          title: '请填写其他成本！',
          icon: 'none',
        })
        return false
      }
			// 项目预算表
			if (this.basicForm.categoryName) {
				if (this.isProjectInformation) {
					if (!this.basicForm.projectBudgetFile) {
						uni.showToast({
						  title: '请选择项目预算表！',
						  icon: 'none',
						})
						return false
					}
				} else {
					if (!this.basicForm.productBudgetFile) {
						uni.showToast({
						  title: '请选择生产绩效表！',
						  icon: 'none',
						})
						return false
					}
				}
			}

      if (!this.basicForm.templateId) {
        uni.showToast({
          title: '请选择任务进度！',
          icon: 'none',
        })
        return
      }

      const total = this.distributionDtList.reduce((total, item) => {
        total += Number(item.contractAmount)
        return total
      }, 0)
      if (total !== this.basicForm.contractAmount) {
        uni.showToast({
          title: '合同分配额总和必须等于任务委托合同额！',
          icon: 'none',
        })
        return
      }
      var isSuccess = true
      var num = 0
      if (this.progressNodeVoList && this.progressNodeVoList.length) {
        num = this.progressNodeVoList.findIndex((item) => {
          return !item.taskNodeId
        })
        if (num == -1) {
          isSuccess = true
        } else {
          isSuccess = false
        }
      }
      if (!isSuccess) {
        uni.showToast({
          title: '请完善款项进度！',
          icon: 'none',
        })
        return false
      }
      var params = this.basicForm
      if (this.distributionDtList && this.distributionDtList.length) {
        params.distributionDtList = this.distributionDtList
      }
      if (this.progressNodeVoList && this.progressNodeVoList.length) {
        this.progressNodeVoList.map((value) => {
          value.taskId = this.basicForm.taskId
          return value
        })
      }
      params.progressNodeVoList = this.progressNodeVoList // 款项详情
      params.progressVoList = this.progressVoList // 任务进度
      erpOmcTaskDistributionEdit(params).then((res) => {
        if (res.success) {
          this.$refs.uToast.show({
          	message: '提交成功',
          	type: 'success',
          	complete () {
          		_this.onAudit()
          	}
          })
          this.isSubmit = true
        } else {
          this.$refs.uToast.show({
            message: res.message,
            type: 'error',
          })
        }
      })
    },

    onAudit() {
      if (!this.isSubmit) {
        uni.showToast({
          title: '请完善表单后审核',
          icon: 'none',
        })
        return false
      }
      var that = this
      uni.navigateTo({
        url: '/pages/synergy/ErpOmcTaskDistributionForm' + `?item=${encodeURIComponent(JSON.stringify(this.model).replace(/%/g, '%25'))}`,
        success: function (data) {
          // 通过eventChannel向被打开页面传送数据
          var params = {
            nodeObj: encodeURIComponent(JSON.stringify(that.nodeObj).replace(/%/g, '%25')),
            tabvalue: that.tabvalue,
          }
          data.eventChannel.emit('sendMessage', params)
        },
        fail: function (err) {
          this.$refs.uToast.show({
            message: '请联系管理员配置',
            type: 'error',
          })
        },
      })
    },
  },
}
</script>

<style lang="scss" scoped>
@import url("@/assets/inputStyle.scss");
.basic-style {
  background: #ffffff;
  margin: 20rpx;
  border-radius: 20rpx;
  padding: 16rpx 32rpx;
  box-shadow: 0px 4px 20px 0px rgba(0, 0, 0, 0.1);
}
// 基本信息
.basic-title {
  font-size: 16px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 600;
  color: #333333;
  line-height: 22px;
  padding-bottom: 16rpx;
}
.basic-border {
  border-bottom: 1px solid #f2f2f2;
}
.basic-padding {
  padding-top: 16rpx;
}

// 评测信息
.info-title {
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #171717;
  line-height: 40rpx;
  padding-bottom: 16rpx;
}

// 评测结果
.result-style {
  font-size: 12px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #b2b2b2;
}

.inforamtion {
  margin-top: 10rpx;
  padding: 10rpx;
  border-radius: 15rpx;
  box-shadow: 0px 4px 20px 0px rgba(0, 0, 0, 0.1);
}
.option {
  display: flex;
  margin-bottom: 4rpx;
  width: 600rpx;

  .lf {
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #b2b2b2;
    white-space: nowrap;
  }
  .rl {
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #7f7f7f;
    margin-left: 16rpx;
  }
}
</style>
